package com.huilai.platform.country_platform.repository;

import com.huilai.platform.country_platform.model.PartyActivities;
import com.huilai.platform.country_platform.model.VillageActivities;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;

/**
 * 作者：洪霓
 * 日期：2023/3/6
 * 注释：
 */
public interface PartyActivitiesReposity extends JpaRepository<PartyActivities, Integer>, JpaSpecificationExecutor<PartyActivities> {

    @Modifying(clearAutomatically = true)
    @Transactional
    @Query(value = "insert into party_activities(image, title, `describe`, file, content_type)" +
            "values(:#{#partyActivities.image},:#{#partyActivities.title},:#{#partyActivities.describe},:#{#partyActivities.file},:#{#partyActivities.contentType})", nativeQuery = true)
    Integer addPartyActivities(PartyActivities partyActivities);

    @Modifying(clearAutomatically = true)
    @Transactional
    @Query(value = "update party_activities pa set pa.image = :#{#partyActivities.image}, " +
            "pa.title = :#{#partyActivities.title}, " +
            "pa.describe = :#{#partyActivities.describe}, " +
            "pa.file = :#{#partyActivities.file}, " +
            "pa.content_type = :#{#partyActivities.contentType} where pa.id = :#{#partyActivities.id}",nativeQuery = true)
    Integer updateActivities(PartyActivities partyActivities);

    @Modifying(clearAutomatically = true)
    @Transactional
    @Query("delete from PartyActivities pa where pa.id = :id")
    Integer deleteActivitiesById(Integer id);
}
